using DG.Tweening;
using UnityEngine;

public class ItemSpawner : MonoBehaviour
{
    public PropPrefab[] propPrefabs; // 存储不同种类的物品预制体数组

    // 初始化生成物品的方法
    public void DropItems()
    {
        foreach (var propPrefab in propPrefabs)
        {
            if (Random.Range(0f, 100f) <= propPrefab.dropPercentage) // 根据掉落概率生成物品
            {
                //生成随机的数量
                int Count = Random.Range(propPrefab.minCount, propPrefab.maxCount + 1);
                for (int i = 0; i < Count; i++){
                    Instantiate(propPrefab.prefab, transform.position, Quaternion.identity);
                }
                
            }
        }
    }
}

[System.Serializable] // Unity 可以序列化该类以在编辑器中显示
public class PropPrefab
{
    public GameObject prefab; // 物品的预制体

    [Range(0f, 100f)] public float dropPercentage; // 掉落的概率范围 0% 到 100%
    public int maxCount = 1;//生成最大数量
    public int minCount = 1;//生成最小数量
}
